Dialog Boxes


JavaScript provides three types of dialog boxes: alert, confirm, and prompt.

1. Alert Box

The alert box displays a simple message:

alert('This is an alert box!');

2. Confirm Box

The confirm box asks the user for confirmation:

const userConfirmed = confirm('Do you want to proceed?');
if (userConfirmed) {
    console.log('User chose to proceed.');
} else {
    console.log('User chose to cancel.');
}

3. Prompt Box

The prompt box asks the user for input:

const userName = prompt('What is your name?');
if (userName) {
    console.log('Hello, ' + userName + '!');
} else {
    console.log('User did not enter a name.');
}